//
//  MeViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/2/28.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "MeViewController.h"


#import "JobViewController.h"
#import "ClientViewController.h"
#import "HouseViewController.h"
#import "PersonageViewController.h"
#import "MainTabBar.h"
#import "MainNavigationController.h"
@interface MeViewController ()<MainTabBarDelegate>


@property(nonatomic, weak)MainTabBar *mainTabBar;



@end

@implementation MeViewController
//解决iPhone X 底部tabbar 在界面返回的时候 出现重影的问题
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    for (UIView *view in self.tabBar.subviews) {
        if (![view isKindOfClass:[MainTabBar class]]) {
            [view removeFromSuperview];
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    MainTabBar *mainTabBar = [[MainTabBar alloc]init];
    mainTabBar.frame = self.tabBar.bounds;
    mainTabBar.delegate = self;
    [self.tabBar addSubview:mainTabBar];
    _mainTabBar =mainTabBar;
    
    NSArray *titleArr = @[@"工作任务",@"客户管理",@"房源销售",@"个人中心"];
    
    NSArray *images = @[@"tab_jobGrey",@"tab_cusGrey",@"tab_houseG",@"tab_mineG"];
 
    NSArray *selectedImages = @[@"tab_job",@"tab_customer",@"tab_house",@"tab_mine"];
    
    JobViewController *jobVC = [[JobViewController alloc] init];
    ClientViewController *clientVC = [[ClientViewController alloc] init];
    HouseViewController *housetVC = [[HouseViewController alloc] init];
    PersonageViewController *personageVC = [[PersonageViewController alloc] init];

    
    NSArray *viewControllers = @[jobVC,clientVC,housetVC,personageVC];
    
    for (int i = 0; i<viewControllers.count; i++) {
        UIViewController *childVc = viewControllers[i];
        MainNavigationController *nav = [[MainNavigationController alloc] initWithRootViewController:childVc];
        childVc.tabBarItem.image = [UIImage imageNamed:images[i]];
        childVc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImages[i]];
        childVc.tabBarItem.title = titleArr[i];
        [self.mainTabBar addTabBarButtonWithTabBarItem:childVc.tabBarItem];
        [self addChildViewController:nav];
    }

    
}

- (void)tabBar:(MainTabBar *)tabBar didSelectButtonFrom:(long)fromBtnTag to:(long)toBtnTag{
    self.selectedIndex = toBtnTag;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
